﻿@model OrderModel
@using Telerik.Web.Mvc.UI;
@{
    //page title
    ViewBag.Title = T("Admin.Orders.EditOrderDetails").Text;
}
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "order-form" }))
{
    <div class="section-header">
        <div class="title">
            <img src="@Url.Content("~/Administration/Content/images/ico-sales.png")" alt="" />
            @T("Admin.Orders.EditOrderDetails") - @Model.Id @Html.ActionLink("(" + T("Admin.Orders.BackToList") + ")", "List")
        </div>
        <div class="options">
            @if (!Model.IsLoggedInAsVendor)
            {
                <a href="@Url.Action("PdfInvoice", new { orderId = Model.Id })" class="t-button">@T("Admin.Orders.PdfInvoice")</a>
            }
            @if (!Model.IsLoggedInAsVendor)
            {
                <span id="order-delete" class="t-button">@T("Admin.Common.Delete")</span>
            }
            <input type="submit" id="btnRefreshPage" name="btnRefreshPage" style="display: none" />
            <script type="text/javascript">
                $(document).ready(function () {
                    $('#btnRefreshPage').click(function () {
                        //refresh page
                        location.reload();
                    });
                });
            </script>
        </div>
    </div>
    
    @Html.ValidationSummary(false)

@Html.Telerik().TabStrip().Name("order-edit").Items(x =>
{
    x.Add().Text(T("Admin.Orders.Info").Text).Content(TabInfo().ToHtmlString());
    x.Add().Text(T("Admin.Orders.BillingInfo").Text).Content(TabBillingInfo().ToHtmlString());
    x.Add().Text(T("Admin.Orders.ShippingInfo").Text).Content(TabShippingInfo().ToHtmlString());
    x.Add().Text(T("Admin.Orders.Products").Text).Content(TabProducts().ToHtmlString());
    if (!Model.IsLoggedInAsVendor)
    {
        x.Add().Text(T("Admin.Orders.OrderNotes").Text).Content(TabOrderNotes().ToHtmlString());
    }

    //generate an event
    EngineContext.Current.Resolve<IEventPublisher>().Publish(new AdminTabStripCreated(x, "order-edit"));
}).ClientEvents(events => events.OnSelect("telerik_on_tab_select")).SetSelectedTabIndex(GetSelectedTabIndex())

    @*save selected tab index*@
	<input type="hidden" id="selected-tab-index" name="selected-tab-index" value="@(GetSelectedTabIndex())">

}
@Html.DeleteConfirmation("order-delete")
@helper TabInfo()
{
    @Html.Partial("_OrderDetails.Info", Model)
}
@helper TabBillingInfo()
{
    @Html.Partial("_OrderDetails.Billing", Model)
}
@helper TabShippingInfo()
{
    @Html.Partial("_OrderDetails.Shipping", Model)
}
@helper TabProducts()
{
    @Html.Partial("_OrderDetails.Products", Model)
}
@helper TabOrderNotes()
{
    @Html.Partial("_OrderDetails.Notes", Model)
}
